package morning.cat.demo2.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * socket服务端
 * 
 * @author mengzhang6
 *
 */
public class Server {

	/**
	 * 启动端口
	 */
	final static int PROT = 8765;

	public static void main(String[] args) {

		ServerSocket server = null;
		try {
			server = new ServerSocket(PROT);
			System.out.println(" server start .. ");

			while (true) {
				// 进行阻塞
				Socket socket = server.accept();
				// 新建一个线程执行客户端的任务
				new Thread(new ServerHandler(socket)).start();
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (server != null) {
				try {
					server.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			server = null;
		}

	}
}
